package com.coin.exchanges.view.user

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.coin.exchanges.R
import com.coin.exchanges.cache.PreferenceManager
import com.coin.exchanges.model.okex.response.FuturesRateRes
import com.coin.exchanges.net.RetrofitFactory
import com.coin.exchanges.presenter.TestPresenter
import com.coin.exchanges.view.user.bean.CompanyNoticeBean
import com.coin.libbase.view.activity.JToolbarActivity
import io.reactivex.SingleObserver
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_company_notice.*

class CompanyNoticeActivity : JToolbarActivity<TestPresenter>()  {
    override fun getLayout(): Int {
        return R.layout.activity_company_notice
    }

    override fun initIntent(intent: Intent?) {
    }

    override fun initView() {
        setToolbarBackground(R.color.white)
        title = "公司公告"
    }

    override fun initData() {
        GetCompanyNoticeData()
    }

    private fun GetCompanyNoticeData(){
        RetrofitFactory
                .getOkExApiService()
                .companyNotice
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : SingleObserver<CompanyNoticeBean> {
                    override fun onSubscribe(d: Disposable) {

                    }

                    override fun onSuccess(futuresRateRes: CompanyNoticeBean) {
                        if(futuresRateRes.result==1){
                            mCompanyData.text =futuresRateRes.data[0].Date
                            mCompanyContent.text =futuresRateRes.data[0].Content
                        }else{
                            mCompanyContent.text="暂无公告"
                        }

                    }

                    override fun onError(e: Throwable) {
                        Log.i(TAG, "onError: " + e.message)
                    }
                })
        }
}
